package MyApp;
import com.example.myapplication.R;
import com.example.myapplication.zhq;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
public class Welcome extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

        // 初始化按钮并设置点击事件
        setupButtonClickListener(R.id.feature_button_1, Enerage.class);
        setupButtonClickListener(R.id.feature_button_2, BMI.class);
        setupButtonClickListener(R.id.feature_button_3, Food.class);
        setupButtonClickListener(R.id.feature_button_4, MemoActivity.class);



        // 热量查询按钮点击事件
        Button feedbackButton = findViewById(R.id.feedback_button);
        feedbackButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Welcome.this,MyActivity .class);//FeedbackActivity
                startActivity(intent);
            }
        });

        // 水果热量查询
        Button myButton = findViewById(R.id.my_button);
        myButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Welcome.this, MyActivity2.class);//MyActivity
                startActivity(intent);
            }
        });
    }

    // 设置按钮点击事件的通用方法
    private void setupButtonClickListener(int buttonId, Class<?> targetActivityClass) {
        Button button = findViewById(buttonId);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Welcome.this, targetActivityClass);
                startActivity(intent);
            }
        });
    }
}